<template>
  <div ref="bar" style="width: 400px; height: 400px"></div>
</template>

<script>
export default {
  name: "chart",
  props: ["bar"],
  methods: {
    initEcharts() {
      let myEcharts = this.$echarts.init(this.$refs.bar);
      let option = {
        title: {
          text: "茶叶种类销售量",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        xAxis: {
          type: "category",
          data: ["红茶", "黑茶", "绿茶", "黄茶", "乌龙茶", "白茶"],
        },
        yAxis: {
          type: "value",
        },
        legend: {},
        series: [
          {
            name: "茶叶",
            type: "bar",
            data: this.bar || [23, 33, 45, 56, 78],
          },
        ],
      };
      myEcharts.setOption(option);
    },
  },
  mounted() {
    // console.log("this.bar:", this.bar);
    setTimeout(() => {
      this.initEcharts();
    }, 50);

    // console.log("this.bar", this.bar);
  },
  updated() {
    this.initEcharts();
  },
};
</script>

<style>
</style>